# -*- coding: UTF-8 -*-
"""
The fabric tasks I use to manage my Django projects.
Use at your own risk.

To be used by creating a `fabfile.py` with the following two line::

  from garden.fablib import *
  setup_from_root(__file__)
  env.django_projects.append('/home/luc/mypy/lino_local/demo')
  
Where "foobar" is the name of your main package.
  
This fablib uses the following `env` keys:

- `django_projects` : a list of absolute directory paths 

- (consult the source code)

:copyright: Copyright 2013 by Luc Saffre.
:license: BSD, see LICENSE for more details.
"""
import os
import sys
import doctest
import pkg_resources
import textwrap

#~ def clean_sys_path():
    #~ # print sys.path
    #~ if sys.path[0] == '':
        #~ del sys.path[0]
        #~ print "Deleted working directory from PYTHONPATH"


import datetime
import unittest
#~ import subprocess
from setuptools import find_packages
from unipath import Path

from atelier import rstgen

from garden import Project


from fabric.api import env, local, task, prompt
from fabric.utils import abort, fastprint, puts, warn
from fabric.contrib.console import confirm
from fabric.api import lcd


def setup_from_root(filename):
    env.django_projects = []
    
    
@task(alias='summary')
def summary(*cmdline_args):
    """Print a summary to stdout."""
    headers = (
      'path','project_name','hostname')

    def cells(prj):
        return [
            prj.project_dir,
            prj.project_name,
            prj.hostname]
        
    print rstgen.table(headers,[cells(Project(p)) for p in env.django_projects])
    


